# 1.导包
import requests

# 2.创建封装方法的类
import app


class EmpApi:
    def __init__(self,token):
        self.url_all = app.BASE_HOST + "/api/sys/user"
        self.url_one = app.BASE_HOST + "/api/sys/user/"
        self.header_dict = {"Authorization": token}

    # 3.封装新增员工接口
    # def add_Emp(self, token, json_dict):
    def add_Emp(self, json_dict):
        # 定义一个字典变量,用来接收请求头的数据
        # header_dict = {"Authorization": token}
        # 请求路径，请求头，请求体json_dict
        return requests.post(url=self.url_all, headers=self.header_dict, json=json_dict)
        # return requests.post(url=self.url_all, headers=header_dict, json=json_dict)

    # 4.封装查询员工接口
    # def query_Emp(self, token, id):
    def query_Emp(self,id):
        # 定义一个字典变量,用来接收请求头的数据
        # header_dict = {"Authorization": token}
        return requests.get(url=self.url_one + str(id), headers=self.header_dict)
        # return requests.get(url=self.url_one + str(id), headers=header_dict)

    # 5.封装修改员工接口
    # def updata_Emp(self, token, id, json_dict):
    def update_Emp(self,id, json_dict):
        # 定义一个字典变量,用来接收请求头的数据
        # header_dict = {"Authorization": token}
        # 请求路径，请求头，请求体json_dict
        return requests.put(url=self.url_one + str(id), headers=self.header_dict, json=json_dict)
        # return requests.put(url=self.url_one + str(id), headers=header_dict, json=json_dict)

    # 6.封装删除员工接口
    # def del_Emp(self, token, id):
    def del_Emp(self,id):
        #     定义一个字典变量,用来接收请求头的数据
        # header_dict = {"Authorization": token}
        return requests.delete(url=self.url_one + str(id), headers=self.header_dict)
        # return requests.delete(url=self.url_one + str(id), headers=header_dict)
